package oberver.example;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：LJ
 * @Description：
 * @Date: 2017/11/28
 * @Modified By:
 */
public class HanFeiZi implements Observable, IHanFeizi {

    @Override
    public void haveBreakfast() {
        System.out.println("韩非子:开始吃饭了...");
        notifyObservers("韩非子在吃饭");
    }

    @Override
    public void haveFun() {
        System.out.println("韩非子:开始娱乐了...");
        notifyObservers("韩非子在娱乐");
    }


    private List<Observer> list = new ArrayList<Observer>();

    @Override
    public void addObserver(Observer observer) {
        list.add(observer);
    }

    @Override
    public void deleteObserver(Observer observer) {
        list.remove(observer);
    }

    @Override
    public void notifyObservers(String context) {
        for (Observer o : list) {
            o.update(context);
        }
    }
}
